<?php

namespace App\Http\Controllers\Customer;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Rules\PhoneRule;
use ValiDate;
use App\Facades\Services\CollectionService;

class CollectionController extends Controller
{
    public function addCollection(Request $request){

    	$rules = [
    		'name' => 'required',
    		'phone' => ['required',new PhoneRule ],
    		'address' => 'required'
    	];

    	ValiDate::validate($request,$rules);

    	$data = $request->all();

    	CollectionService::addCollection($data);

    	return formatJsonResponse();
    }

    public function getCollection(){
    	return formatJsonResponse(CollectionService::getCollection());
    }

    public function updateCollection(Request $request){

    	$rules = [
    		'name' => 'required',
    		'phone' => ['required',new PhoneRule ],
    		'address' => 'required'
    	];

    	ValiDate::validate($request,$rules);

    	$data = $request->all();

    	CollectionService::updateCollection($data);

    	return formatJsonResponse();
    }
}
